/*
 * dac.h
 *
 * Created: 6/18/2013 11:25:02 PM
 *  Author: Tim
 */ 


#ifndef DAC_H_
#define DAC_H_

#include <inttypes.h>
#include "../../packets/status.h"

#define waveFormTableSize	256

typedef struct
{
	volatile uint16_t  *tableBegin;			//pointer to the beginning of the table
	volatile uint16_t  *tableEnd;			//pointer to the end of the table (tableDepth)
	volatile uint16_t  *dacData;			//pointer to current sample
	volatile uint8_t  tableDepth;			//size of the waveForm
	uint16_t waveData[waveFormTableSize];	//where the waveform data is stored
}dacTable_t;

typedef enum{
	NULL_WAVE		=	0,
	SINE_WAVE		=	1,
	SQUARE_WAVE		=	2,
	SAWTOOTH_WAVE	=	3,
	TRIANGLE_WAVE	=	4	
}dacWave_t;

typedef enum{
	DAC_CH0_bp = 0x01,
	DAC_CH1_bp = 0x02
	}DACM_t;

typedef enum{
	DAC_CH0_msk = 0x00,
	DAC_CH1_msk = 0x01
}DACN_t;

void dacSetup();

//used to generate the waveform table for the dac channel

status_t dacWaveformTableInit(uint8_t dacCh,dacWave_t wave, uint16_t freq, uint16_t amp, uint16_t offset);

void dacUpdate(uint8_t dacCh, uint16_t data);

uint16_t dacSampleTable(uint8_t dacCh);

void fillTable_sine(dacTable_t *table, uint16_t freq, uint16_t amp, uint16_t offset);
void fillTable_square(dacTable_t *table, uint16_t freq, uint16_t amp, uint16_t offset);
void fillTable_sawtooth(dacTable_t *table, uint16_t freq, uint16_t amp, uint16_t offset);
void fillTable_triangle(dacTable_t *table, uint16_t freq, uint16_t amp, uint16_t offset);


#endif /* DAC_H_ */